package org.apache.doris.demo.spring.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.doris.demo.spring.model.Tag;
import org.apache.doris.demo.spring.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class SearchController {
    @Autowired
    public TagService tagService;
//    @GetMapping("/search")
//    public String search(Model model) {
//        List<Tag> tags = tagService.list(null);
//        model.addAttribute("tags", tags);
//        return "index";
//    }
    @ResponseBody
    @GetMapping("/search/{query}")
    public List<Tag> search(@PathVariable("query") String query, Model model) {
        // TODO: 实现搜索逻辑，将搜索结果添加到Model中
        List<Tag> tags = tagService.list(new QueryWrapper<Tag>().like("tag_value",query));
        return tags;
    }
}
